<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<!DOCTYPE html>
<html>
	<head>
	<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<title>学生信息管理</title>
	<meta name="description" content="这是一个 index 页面">
	<meta name="keywords" content="index">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<meta name="renderer" content="webkit">
	<meta http-equiv="Cache-Control" content="no-siteapp" />
	<link rel="icon" type="image/png" href="${ctx}/assets/i/favicon.png">
	<link rel="apple-touch-icon-precomposed" href="${ctx}/assets/i/app-icon72x72@2x.png">
	<meta name="apple-mobile-web-app-title" content="Amaze UI" />
	<link rel="stylesheet" href="${ctx}/assets/css/amazeui.datatables.min.css" />
	<script src="${ctx}/assets/js/echarts.min.js"></script>
	<link rel="stylesheet" href="http://cdn.amazeui.org/amazeui/2.7.2/css/amazeui.min.css" />
	<script src="https://cdn.bootcss.com/jquery/2.2.3/jquery.js"></script>
	<link rel="stylesheet" href="${ctx}/assets/css/app.css">
</head>
	<body data-type="widgets">
		<script src="${ctx}/assets/js/theme.js"></script>
		<%@ include file="../../jspf/adminheader.jspf"%>
		<div class="am-g tpl-g" >
			<!-- 内容区域 -->
			<div class="row-content" style="margin-left:240px;">
				<div class="row-content am-cf">
					<div class="row">
						<div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
							<div class="widget am-cf">
								<div class="widget-head am-cf">
									<div class="widget-title  am-cf">意向岗位管理</div>
								</div>
								<div class="am-u-sm-3">
									<label for="dept">部门&nbsp;&nbsp;</label><select data-am-selected name="dept" id="dept"></select>
								</div>
								<div class="am-u-sm-3">
									<label for="clazz">班级&nbsp;&nbsp;</label><select data-am-selected name="clazz" id="clazz"></select>
								</div>
								<div class="am-u-sm-3">
									<label for="job">岗位&nbsp;&nbsp;</label><select data-am-selected name="job" id="job"></select>
								</div>
								<div class="am-u-sm-1">
									<a class="am-btn am-icon-pencil" href="#" onclick="refresh()">查询</a>
								</div>
								<div class="am-u-sm-1">
									<a class="am-btn am-icon-pencil" href="#" onclick="exportxls()">导出</a>
								</div>
								<div class="widget-body  am-fr">
									<div class="am-u-sm-12">
										<table id="example"
										class="am-table am-table-compact am-table-striped tpl-table-black">
											<thead>
												<tr>
													<th>学号</th>
													<th>姓名</th>
													<th>部门</th>
													<th>班别</th>
													<th>首选岗位</th>
													<th>次选岗位</th>
													<th>备选岗位</th>
													<th>操作</th>
												</tr>
											</thead>
											<tfoot>
												<tr>
													<th>学号</th>
													<th>姓名</th>
													<th>部门</th>
													<th>班别</th>
													<th>首选岗位</th>
													<th>次选岗位</th>
													<th>备选岗位</th>
													<th>操作</th>
												</tr>
											</tfoot>
										</table>
									</div>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
		<script src="http://cdn.amazeui.org/amazeui/2.7.2/js/amazeui.min.js"></script>
		<script
			src="${ctx}/assets/js/amazeui.datatables.min.js"></script>
		<script
			src="${ctx}/assets/js/dataTables.responsive.min.js"></script>
		<script src="${ctx}/assets/js/app.js"></script>
		<script type="text/javascript">
			function refresh(){
				var table = $('#example').DataTable();
				table.draw();
			}
			jQuery.download = function(url, data, method){
			    // 获得url和data
			    if( url && data ){ 
			        // data 是 string 或者 array/object
			        data = typeof data == 'string' ? data : jQuery.param(data);
			        // 把参数组装成 form的  input
			        var inputs = '';
			        jQuery.each(data.split('&'), function(){ 
			            var pair = this.split('=');
			            inputs+='<input type="hidden" name="'+ pair[0] +'" value="'+ pair[1] +'" />'; 
			        });
			        // request发送请求
			        jQuery('<form action="'+ url +'" method="'+ (method||'post') +'">'+inputs+'</form>')
			        .appendTo('body').submit().remove();
			    };
			};
			function exportxls(){
				var data = 	'clazz='+$('#clazz').val()+'&dept='+$('#dept').val();	
				$.download('${ctx}/wechat/favjob/export',data,'post' );
			}
			$(document).ready(function() {
				$('#example').dataTable({
					"processing" : true,
					"serverSide" : true,
					"searching": false,
					"bLengthChange": false,
					"ajax" : {
						"type" : "POST",
						"url" : "getData",
						"data" : function(b){
							b.clazz=$('#clazz').val();
							b.dept=$('#dept').val();
							b.job=$('#job').val()
						},
					},
					 "columns": [ //表格要显示的列定义(字段名称做了处理)
		                    { "data": "id"},
		                    { "data": "name"},
		                    { "data": "dept" },
		                    { "data": "clazz" },
		                    { "data": "favJob",
		                    	render: function(data, type, row,meta){
			                    	  if(data==null || data.firstJob== null){
						            		return '';
						            	}
						            	else{
						            		return data.firstJob.name;
						            	}
			                      }
			                 },	
			                 { "data": "favJob",
			                    	render: function(data, type, row,meta){
				                    	  if(data==null || data.secondJob== null){
							            		return '';
							            	}
							            	else{
							            		return data.secondJob.name;
							            	}
				                      }
				               },
				               { "data": "favJob",
			                    	render: function(data, type, row,meta){
				                    	  if(data==null || data.thirdJob== null){
							            		return '';
							            	}
							            	else{
							            		return data.thirdJob.name;
							            	}
				                      }
				             }
		                    //其余字段定义省略
		            ],
		           // "aaSorting": [ //指定排序的列（索引从0开始）及规则
	               //    [2, "desc" ]
	               //  ],
		          //自定义字段
					columnDefs:[
						 { 
							 targets: 7,
							 render: function ( data, type, row, meta ) {
								 if( row.favJob==null)
									 return '';
								 else
		                        return '<a class="am-btn am-icon-trash" href="delete?id='+ row.favJob.id + '">删除</a>';
		                     }
		                 },
		                { "orderable": false, "targets": 7 }
		            ]
				});
			})
			</script>
			<script type="text/javascript">
		//获取班级的ajax
		function getclazzes() {
			$.ajax({
				url : "${ctx}/std/getclazzes",
				type : "get",
				async : false,
				success : function(data) {
					$("#clazz").empty();
					$("#clazz").append('<option></option>');
					for ( var i in data) {
							$("#clazz").append("<option value='"+data[i].name+"'>"+data[i].name+"</option>");
					}
				}
			});
		}
		function getdepts() {
			$.ajax({
				url : "${ctx}/std/getdepts",
				type : "get",
				async : false,
				success : function(data) {
					$("#dept").empty();	
					$("#dept").append('<option></option>');
					for ( var i in data) {
						$("#dept").append("<option value='"+data[i].name+"'>"+data[i].name+"</option>");
					}
				}
			});
		}
		function getJobs() {
			$.ajax({
				url : "${ctx}/wechat/favjob/getjobs",
				type : "post",
				async : false,
				success : function(data) {
					$("#job").empty();
					$("#job").append('<option></option>');
					for ( var i in data) {
						$("#job").append("<option value='"+data[i].id+"'>"+data[i].name+"</option>");
					}
				}
			});
		}
		getclazzes();
		getdepts();
		getJobs();
	</script>
	</body>

</html>